﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows;

namespace Kugar.UI.WinForm.ContainerEx
{
    public class BorderPanel:Panel
    {
        private float borderSize;
        private Color borderColor;
        private Pen drawBorderPen;


        public BorderPanel()
        {
            base.BorderStyle = BorderStyle.None;
        }

        /// <summary>
        ///   The border's thickness
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("The border's thickness")]
        [DefaultValue(1f)]
        public float BorderSize
        {
            get { return this.borderSize; }
            set
            {
                this.borderSize = value;
                //if (value == 0)
                //{
                //    //If border size equals zero, disable the
                //    // border by setting it as transparent
                //    this.drawPen.Color = Color.Transparent;
                //}
                //else
                //{
                //    this.drawPen.Color = this.BorderColor;
                //    this.drawPen.Width = value;
                //}

                this.OnTextChanged(EventArgs.Empty);
            }
        }

        /// <summary>
        ///   The border color of this component
        /// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [DefaultValue(typeof(Color), "White")]
        [Description("The border color of this component")]
        public Color BorderColor
        {
            get { return this.borderColor; }
            set
            {
                this.borderColor = value;

                //if (this.BorderSize != 0)
                    this.drawBorderPen.Color = value;

                this.Invalidate();
            }
        }

        private BorderStyle _borderStyle;
        public new BorderStyle BorderStyle
        {
            get
            {
                return _borderStyle;
            }
            set
            {
                if (_borderStyle!=value)
                {
                    _borderStyle = value;
                    this.Invalidate();
                }
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (this._borderStyle== BorderStyle.FixedSingle)
            {
                ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, borderColor,ButtonBorderStyle.Solid);
            }
            else if(_borderStyle== BorderStyle.Fixed3D)
            {
                ControlPaint.DrawBorder3D(e.Graphics,e.ClipRectangle);
            }

        }
    }
}
